import request from '@/utils/request'
// 获取路由
export function getRouters(roleId) {
  return request({
    url: '/role/getRouters',
    method: 'get',
    params: { roleId }
  })
}

// 获取权限
export function getPermissions(roleId) {
  return request({
    url: '/role/getPermissions',
    method: 'get',
    params: { roleId }
  })
}
// 获取角色列表
export function roleList(data) {
  return request({
    url: '/role/list',
    method: 'post',
    data
  })
}
// 添加角色
export function addRole(data, headers) {
  return request({
    url: '/role/addnew',
    method: 'post',
    data,
    headers
  })
}
// 删除角色
export function removeRole(id, headers) {
  return request({
    url: '/role/delete',
    method: 'get',
    params: { id },
    headers
  })
}
// 获取角色
export function getRoleById(id) {
  return request({
    url: '/role/get',
    method: 'get',
    params: { id }
  })
}
// 修改角色
export function updateRole(data, headers) {
  return request({
    url: '/role/update',
    method: 'post',
    data,
    headers
  })
}
// 通过用户ID获取角色
export function getRolesByUserId(userId, headers) {
  return request({
    url: '/role/getRolesByUserId',
    method: 'get',
    params: { userId },
    headers
  })
}
// 为用户授权角色
export function grantRole(data, headers) {
  return request({
    url: '/user/grant',
    method: 'post',
    data,
    headers
  })
}
// 通过角色id获取权限
export function getPermissionByRoleId(roleId) {
  return request({
    url: '/menu/menuperms',
    method: 'get',
    params: { roleId }
  })
}
// 授权菜单和权限
export function grantPerssion(data, headers) {
  return request({
    url: '/role/grant',
    method: 'post',
    data,
    headers
  })
}
